'''
加班管理测试
'''
from selenium.webdriver.common.by import By

from Lib.base.page_object.attendance.overtime import OverTime
import allure
from Lib.common.assert_class import AssertClass
import pytest
from Lib.common.get_data_by_mysql import MysqlAssert


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestOverTime.assertClass = AssertClass(login)
    TestOverTime.overTime = OverTime(login)


@allure.feature("加班管理测试")
class TestOverTime:

    @allure.title('筛选加班列表')
    def test_overTime_list(self, login):
        '''
        根据筛选条件筛选加班列表
        :param login:
        :return:
        '''
        with allure.step('根据加班类型查看加班列表'):
            # 调用页面操作方法
            self.overTime.overtime_list_by_status()
            # 断言
            assert_args = (By.XPATH, '//tbody/tr/td[8]//span[text()="已通过"]')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data='已通过')
        with allure.step('根据时间筛选加班列表'):
            # 调用页面操作方法
            self.overTime.overtime_list_by_time()
            # 断言
            assert_args1 = (By.XPATH, '//tbody/tr[1]/td[7]//span')
            assert_args2 = (By.XPATH, '//tbody/tr[2]/td[7]//span')
            self.assertClass.make_assert_by_compare_time(args1=assert_args1, args2=assert_args2)

    @allure.title('搜索加班并查看详情')
    def test_overTime_search_and_detail(self):
        '''
        搜索加班、并查看加班详情
        :return:
        '''
        with allure.step('根据关键词搜索加班'):
            self.overTime.overtime_search()
            assert_args = (By.XPATH, '//tbody/tr/td[2]//span[text()="申请人kb"]')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data='申请人kb')
        with allure.step('查看加班详情'):
            self.overTime.overtime_detail()
            assert_args = (By.XPATH, '//div[@class="overtime-container"]//div[contains(text(), "已通过")]')
            self.assertClass.make_assert_by_elements_text(args=assert_args, assert_data='已通过')


if __name__ == '__main__':
    pytest.main(
        ['-v', '-s', './overtime_test.py::TestOverTime'])
    # pytest.main(['-v', './business_test.py', '--alluredir', '../result', '--clean-alluredir'])
    # os.system(r'copy ..\config\environment.properties ..\result\environment.properties')
    # os.system('allure generate  ../result -o ../report/ --clean')
